from pathlib import Path
import csv
import matplotlib.pyplot as plt
from datetime import datetime
# path = Path('Data visualization/weather.csv')
path = Path('weather.csv')
lines = path.read_text(encoding='utf-8').splitlines()

reader = csv.reader(lines)
header = next(reader)
# print(header)

dates,highs,lows = [],[],[]
for row in reader:
    date = datetime.strptime(row[1],'%Y-%m-%d')
    try:
        date_lower = int(row[3])
        date_high = int(row[2])
    except ValueError:
        print(f"Missing data for {date}") 

    else:
        highs.append(date_high)
        lows.append(date_lower)
        dates.append(date)
print(highs)

# plt.style.use('seaborn')
fig,ax = plt.subplots()

ax.plot(dates,highs,color = 'red',alpha = 0.5)
ax.plot(dates,lows,color = 'blue',alpha = 0.5)
ax.fill_between(dates,highs,lows,facecolor = 'blue',alpha = 0.1)
ax.set_title("Nwyk,2021",fontsize = 15)
ax.set_xlabel("Date",fontsize= 16 )
ax.set_ylabel("Climate",fontsize= 16 )
fig.autofmt_xdate()
ax.tick_params(labelsize = 16)
plt.show()